package cn.mall.bill.service.impl;

import cn.mall.base.utils.PageList;
import cn.mall.bill.domain.Bill;
import cn.mall.bill.mapper.BillMapper;
import cn.mall.bill.query.BillQuery;
import cn.mall.bill.query.BillUserNameQuery;
import cn.mall.bill.service.IBillService;
import cn.mall.base.service.impl.BaseServiceImpl;
import cn.mall.bill.vo.BillVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xizhou
 * @since 2024-04-18
 */
@Service
public class BillServiceImpl extends BaseServiceImpl<Bill> implements IBillService {

    @Autowired
    private BillMapper billMapper;


    @Override
    public PageList<Bill> pageList(BillQuery billQuery) {
        long total = billMapper.loadTotal(billQuery);
        if (total > 0){
            List<Bill> rows = billMapper.pageList(billQuery);
            return new PageList<Bill>(total, rows);
        }
        return new PageList<>();
    }

    @Override
    public BillVo getBillBymoeny(BillVo billVo) {
        BillVo billByr = billMapper.getBillBymoeny(billVo);
        return billByr;
    }

    @Override
    public PageList<Bill> searchByusername(BillUserNameQuery query) {
        if(query.getName()!=null && query.getName()!=""){
            String trim = query.getName().trim();
            query.setName(trim);
        }
        long total = billMapper.loadTotalByusername(query);
        if (total > 0){
            List<Bill> rows = billMapper.pageListByusername(query);
            return new PageList<Bill>(total, rows);
        }
        return new PageList<>();
    }

    @Override
    public void deleteBytime(String time) {
        billMapper.deleteBytime(time);
    }


}
